/*
 * This is a collection of functions and objects for managing the items and categories view 
 * It use a Object Model we will call the the catalog object model. It is like this:
 * class (object)
 *
 * catalog (myCatalog)
 
  
 * catalog
 * catalog::categoriesList
 * catalog::categoriesList::array(category) (categories)
 * catalog::categoriesList::category[x]::itemsList (itemsList)
 * catalog::categoriesList::category[x]::itemsList:array(smallItem) (items)
 
 * orderCatalog
 * orderCatalog::orderCategoriesList (myCategoriesList)
 * orderCatalog::orderCategoriesList::array(orderCategory) (categories)
 * orderCatalog::orderCategoriesList::orderCategory[x]::orderItemsList (itemsList)
 * orderCatalog::orderCategoriesList::orderCategory[x]::orderItemsList:array(smallItem) (items)
 
 * adminCatalog
 * adminCatalog::adminCategoriesList (myCategoriesList)
 * adminCatalog::adminCategoriesList::array(adminCategory) (categories)
 * adminCatalog::adminCategoriesList::adminCategory[x]::adminItemsList (itemsList)
 * adminCatalog::adminCategoriesList::adminCategory[x]::adminItemsList:array(smallItem) (items)
 */
 
 // Equivalent to order.
// In this case there is no subTotal neither any other value so we could avoid this object but it could serve in future
function orderCatalog() {
	this.myCategoriesList=null;
}

orderCatalog.prototype.initAddItemButtons=initAddItemButtons;
orderCatalog.prototype.loadCategories=loadCategories;
orderCatalog.prototype.loadItems=loadItems;
orderCatalog.prototype.loadViewCategoriesList=loadViewCategoriesList;
orderCatalog.prototype.loadViewItemsList=loadViewItemsList;
orderCatalog.prototype.refreshCategoriesListView=refreshCategoriesListView;
orderCatalog.prototype.refreshItemsListView=refreshItemsListView;
 
  // myCatalog is the global variable that contain the catalog object model objects. Any time we need to know the catalog
 // state or to modify any data from it we will do it through this variable. We initialize this variable here.

var myCatalog=new orderCatalog();


/**
 * It sets all form buttons "+ 1 to the cart" for performming the correspondig shopping cart function.
 */
function initAddItemButtons(button) {
	button.onclick=function() {
		this.avoidDubleClick=avoidDubleClick;
		this.createItem=createItem;
		
		if (!("item" in this))  {
			this.item=this.createItem();
		}
		addItemToOrder(this.item);
		calculateOrderPrice();
		showAlertItemAdded(this.item);
		blink(this.getAttribute("myFor"));
		refreshOrderView(this.getAttribute("myFor"));
		this.avoidDubleClick();
		
		function createItem() {
			var my_item=new orderItem();
			my_item.setFromArray(this.smallItem);
			return my_item;
		}
		
		function avoidDubleClick() {
			this.disabled=true;
				function enableButton(myButton) {
					myButton.disabled=false;
				}		
				setTimeout(enableButton,1200, this);
		}

		function showAlertItemAdded(item) {
			var divElement=document.createElement('div');
			divElement.className="alert";
			var sign='+';
			if (item.quantity<0) sign='';
			var textNode=document.createTextNode(sign+item.quantity+" "+item.name);
			var pElement=document.createElement('p');
			pElement.appendChild(textNode);
			divElement.appendChild(pElement);
			var newAlert=document.body.appendChild(divElement);
			newAlert.onclick=function() {
				this.parentNode.removeChild(this);
			}
			setTimeout(removeAlert,1100,divElement);

			function removeAlert(myAlert) {
				myAlert.parentNode.removeChild(myAlert);
			}
		}
						
		function blink(id) {
			this.element=document.getElementById(id);
			this.blink_time=400;
			this.time_limit=3000;
			this.time_count=0;
			this.blinking=blinking;
			this.blinking();
			function blinking(){
				if (this.element.style.visibility=="visible")
					this.element.style.visibility="hidden";
				else element.style.visibility="visible";
				this.time_count+=this.blink_time;
				if (this.time_count>=this.time_limit) {
					this.element.style.visibility="visible";
					return;
				}
				setTimeout("blinking()",blink_time);
			}
		}

		function addItemToOrder(item) {
			if (item) {
				myOrder.myCart.addItem(item);
			}
		}

		function calculateOrderPrice() {
			myOrder.subTotal=myOrder.myCart.sumPrice();
		}
	}
}

// This function sets the categories and subcategories from a object contained that is defined at the string by the standard JSON
// Categories and subcategories are defined normally by steps. That's mean that first we load root categories and then
// subcategories are being loaded at the correspondents categories

function loadCategories(caregoriesString) {
	var categoriesPointer=JSON.parse(caregoriesString);
	if (!categoriesPointer.id) {
		// These are root categories
		myCatalog.myCategoriesList=new orderCategoriesList();
		myCatalog.myCategoriesList.rootCategory=new orderCategory();
		myCatalog.myCategoriesList.rootCategory.id=0;
		for (var i in categoriesPointer.categories) {
			myCatalog.myCategoriesList.rootCategory.categories[i]=new orderCategory();
			myCatalog.myCategoriesList.rootCategory.categories[i].setFromArray(categoriesPointer.categories[i]);
		}
	}
	else {
		// These are subcategories
		for (var i in myCatalog.myCategoriesList.rootCategory.categories) {
			if (myCatalog.myCategoriesList.rootCategory.categories[i].id==categoriesPointer.id && !myCatalog.myCategoriesList.rootCategory.categories[i].categories.length) {
				for (var j in categoriesPointer.categories) {
					var newCategory=new orderCategory();
					newCategory.setFromArray(categoriesPointer.categories[j]);
					myCatalog.myCategoriesList.rootCategory.categories[i].categories.push(newCategory);
				}
				break;
			}
		}
	}
}

// This function load the items in a category from a json formated string with the items

function loadItems(itemsString) {
	var itemPointer=JSON.parse(itemsString);
	// We find the selected category. Other way could be to find it by itemPointer.id == category.id
	var categoryPointer=null;
	for (var i in myCatalog.myCategoriesList.rootCategory.categories) {
		if (myCatalog.myCategoriesList.rootCategory.categories[i].selected) {
			categoryPointer=myCatalog.myCategoriesList.rootCategory.categories[i];
			break;
		}
	}
	for (var i in categoryPointer.categories) {
		if (categoryPointer.categories[i].selected) {
			categoryPointer=categoryPointer.categories[i];
			break;
		}
	}
	// Now we set the items at the selected category
	categoryPointer.itemsList=new orderItemsList();
	for (var i in itemPointer.items) {
		categoryPointer.itemsList.items[i]=new smallItem();
		categoryPointer.itemsList.items[i].setFromArray(itemPointer.items[i]);
	}

}
// This function is to load the categroies List template fro prompting the categories list. 
// It is equivalent to loadViewOrder but for categories
function loadViewCategoriesList(elementId) {
	var myCategoriesContainerElements=document.getElementById(elementId).getElementsByTagName("*");
	//We load the categories list view (template). I make a copy to be independient from the original one that is inserted at the document DOM.

	for (var i in myCategoriesContainerElements) {
		// First we check that getAttribute is a function so there will not be a error when try to exect it
		if (typeof myCategoriesContainerElements[i].getAttribute != 'function') continue;
		if (myCategoriesContainerElements[i].getAttribute("myProperty")=="categoriesList") {
			myCatalog.myCategoriesList.blankView=myCategoriesContainerElements[i].cloneNode(true);
			break;
		}
	}
	
	var myCategoriesListElements=myCatalog.myCategoriesList.blankView.getElementsByTagName("*");
	
	// Now we get a single category's prompt
	for (var i in myCategoriesListElements) {
		if (typeof myCategoriesListElements[i].getAttribute != 'function') continue;
		// We get the category prompt from the categoriesList prompt (template) and save it at myCatalog.myCategoriesList.myCategoryView
		if (myCategoriesListElements[i].getAttribute("myProperty")=="categories") {
			myCatalog.myCategoriesList.myCategoryView=myCategoriesListElements[i].cloneNode(true);
			break;
		}
	}
}
// Equivalent to the above function but for the itemsList
function loadViewItemsList(elementId) {
	// We search for the selected category
	var categoryPointer=null;
	for (var i in myCatalog.myCategoriesList.rootCategory.categories) {
		if (myCatalog.myCategoriesList.rootCategory.categories[i].selected) {
			categoryPointer=myCatalog.myCategoriesList.rootCategory.categories[i];
			break;
		}
	}
	for (var i in categoryPointer.categories) {
		if (categoryPointer.categories[i].selected) {
			categoryPointer=categoryPointer.categories[i];
			break;
		}
	}
	
	var myItemsContainerElements=document.getElementById(elementId).getElementsByTagName("*");
	// Now we get the itemsList prompt
	for (var i in myItemsContainerElements) {
		if (typeof myItemsContainerElements[i].getAttribute != 'function') continue;
		if (myItemsContainerElements[i].getAttribute("myProperty")=="itemsList") {
			categoryPointer.itemsList.blankView=myItemsContainerElements[i].cloneNode(true);
			break
		}
	}

	var myItemListElements=categoryPointer.itemsList.blankView.getElementsByTagName("*");
	// Now we get a single item's prompt
	for (var i in myItemListElements) {
		if (typeof myItemListElements[i].getAttribute != 'function') continue;
		if (myItemListElements[i].getAttribute("myProperty")=="items") {
			categoryPointer.itemsList.myItemView=myItemListElements[i].cloneNode(true);
			break
		}
	}
}

// Equivalent to refreshOrderView but for the categoriesList
function refreshCategoriesListView(elementId) {
	// We get the selected Category
	var categoryPointer=myCatalog.myCategoriesList.rootCategory;
	for (var i in categoryPointer.categories) {
		if (categoryPointer.categories[i].selected) {
			categoryPointer=categoryPointer.categories[i];
			break;
		}
	}
	if (!categoryPointer.id)  {
		// There is not selected category so we prompt the root categories
		for (var i in categoryPointer.categories) {
			categoryPointer.categories[i].mySetView(myCatalog.myCategoriesList.myCategoryView.cloneNode(true));
		}
	}
	else {
		// We prompt the subcategories
		if (categoryPointer.categories.length>0) {
			for (var i in categoryPointer.categories) {
				categoryPointer.categories[i].mySetView(myCatalog.myCategoriesList.myCategoryView.cloneNode(true));
			}
			// As we are printing the subcategories so no subcategory is selected, we make selected the first one
			//var myFirstCategory=categoryPointer.getCategoryByOrder(1);
			var myFirstCategory=categoryPointer.categories[0];
			myFirstCategory.mySetSelected();
		}
	}

	// The different between mySetView and myLoad... functions is that mySet just fills the fields with its own porperties but
	// myLoad fills it with its indexed object view
	myCatalog.myCategoriesList.myLoadCategoriesView(myCatalog.myCategoriesList.blankView.cloneNode(true));
	
	myCategoriesListElements=myCatalog.myCategoriesList.myView.getElementsByTagName("*");
	for (var i in myCategoriesListElements) {
		if (typeof myCategoriesListElements[i].getAttribute != 'function') continue;
		if (myCategoriesListElements[i].getAttribute("myProperty")=="addCategory") {
			if (categoryPointer) myCategoriesListElements[i].href+=categoryPointer.id;
			initLoadingElements(myCategoriesListElements[i]);
			break;
		}
	}
	// We insert the view element at the DOM
	var myCategoriesListContainerElement=document.getElementById(elementId);
	while (myCategoriesListContainerElement.children[0]) myCategoriesListContainerElement.removeChild(myCategoriesListContainerElement.children[0]);
	myCategoriesListContainerElement.appendChild(myCatalog.myCategoriesList.myView);
}
// Equivalent to above function
function refreshItemsListView(elementId) {
	// Method mySetView is instantiated for each item to fill the template and assign it to the smallItem myView variable.
	// We send a clone of myItemsList.myItemView to leave the original intact for further use and also we need to duplicate it for each item.
	var categoryPointer=null;
	for (var i in myCatalog.myCategoriesList.rootCategory.categories) {
		if (myCatalog.myCategoriesList.rootCategory.categories[i].selected) {
			categoryPointer=myCatalog.myCategoriesList.rootCategory.categories[i];
			break;
		}
	}
	for (var i in categoryPointer.categories) {
		if (categoryPointer.categories[i].selected) {
			categoryPointer=categoryPointer.categories[i];
			break;
		}
	}
	
	for (var i in categoryPointer.itemsList.items) {
		categoryPointer.itemsList.items[i].mySetView(categoryPointer.itemsList.myItemView.cloneNode(true));
	}
	categoryPointer.itemsList.myLoadItemsView(categoryPointer.itemsList.blankView.cloneNode(true));
	myItemsListElements=categoryPointer.itemsList.myView.getElementsByTagName("*");
	for (var i in myItemsListElements) {
		if (typeof myItemsListElements[i].getAttribute != 'function') continue;
		if (myItemsListElements[i].getAttribute("myProperty")=="addItem") {
			if (categoryPointer) myItemsListElements[i].href+=categoryPointer.id;
			initLoadingElements(myItemsListElements[i]);
			break;
		}
	}
	var myItemsListContainerElement=document.getElementById(elementId);
	while (myItemsListContainerElement.children[0]) myItemsListContainerElement.removeChild(myItemsListContainerElement.children[0]);
	myItemsListContainerElement.appendChild(categoryPointer.itemsList.myView);
}

// Equivalent to orderItem
function orderCategory() {
	this.id=null;
	this.name=null;
	this.myView=null;
	this.categories= new Array();
	this.parent_id=null;
	this.itemsList=null;
	this.selected=false;
	this.sort_order=null;

	this.mySetSelected=mySetSelected;
	this.mySetUnselected=mySetUnselected;
	this.setFromArray=setFromArray;
	this.myActivate=myActivate;
	

	function mySetSelected() {
		if (this.parent_id==0) {
			var myCategoryElements=this.myView.getElementsByTagName("*");
			for (var j in myCategoryElements) {
				if (typeof myCategoryElements[j].getAttribute != 'function') continue;
				if (myCategoryElements[j].getAttribute("myProperty") == "name") {
					myCategoryElements[j].className+=" selected";
				}
			}
		}
		else {
			this.myView.className+=" selected";
		}
		this.selected=true;
	}
	function mySetUnselected() {
		if (this.parent_id==0) {
			var myCategoryElements=this.myView.getElementsByTagName("*");
			for (var j in myCategoryElements) {
				if (typeof myCategoryElements[j].getAttribute != 'function') continue;
				if (myCategoryElements[j].getAttribute("myProperty") == "name") {
					myCategoryElements[j].className=myCategoryElements[j].className.replace(/selected/,'');
				}
			}
		}
		else this.myView.className=this.myView.className.replace(/selected/,'');
		this.selected=false;
	}
	function myActivate() {
		if (this.parent_id==0) {
			for (var i in myCatalog.myCategoriesList.rootCategory.categories) {
				myCatalog.myCategoriesList.rootCategory.categories[i].mySetUnselected();
			}
		}
		else {
			for (var i in myCatalog.myCategoriesList.rootCategory.categories) {
				if (myCatalog.myCategoriesList.rootCategory.categories[i].id==this.parent_id){
					for (var j in myCatalog.myCategoriesList.rootCategory.categories[i].categories) {
						myCatalog.myCategoriesList.rootCategory.categories[i].categories[j].mySetUnselected();
					}
				}
			}
		}
		this.mySetSelected();
	}
	// An accessory function to fill an object properties with other object properties
	function setFromArray(obj) {
		for(var key in obj) {
			if (key in this)
				this[key] = obj[key];
		}
	}
}

	// This function generates the category view from the template category view
	orderCategory.prototype.mySetView = function(myCategoryView) {
		this.myView=myCategoryView;
		var myCategoryElements=this.myView.getElementsByTagName("*");
		// It will search for the elements that correspond with the properties names to fill them
		for (var j in myCategoryElements) {
			if (typeof myCategoryElements[j].getAttribute != 'function') continue;
			if (myCategoryElements[j].getAttribute("myProperty") in this) {
				myCategoryElements[j].innerHTML=this[myCategoryElements[j].getAttribute("myProperty")];
			}
			// It modifies the href of the category name for adding it the category id that it is necessary for the destination href script to identify the category
			// and sets the link action in a smooth different than usual for the activation when click
			if (myCategoryElements[j].getAttribute("myProperty") == "name") {
				myCategoryElements[j].href=myCategoryElements[j].href+this.id;
				myCategoryElements[j].thisCategory=this;
				initLoadingElements(myCategoryElements[j]);
				myCategoryElements[j].onclick=function () {
					this.thisCategory.myActivate();
					return this.request();
				}
			}
		}
	}

function orderCategoryAdmin() {
	orderCategory.call(this);
}
orderCategoryAdmin.prototype=Object.create(orderCategory.prototype);

orderCategoryAdmin.prototype.constructor=orderCategory;

orderCategoryAdmin.prototype.mySetView = function (myCategoryView) {
	orderCategory.mySetView.call(this,myCategoryView);
		var myCategoryElements=this.myView.getElementsByTagName("*");
		// It will search for the elements that correspond with the properties names to fill them
		for (var j in myCategoryElements) {
	
			// It defines the edit category button performance
			if (myCategoryElements[j].getAttribute("myProperty") == "editCategory") {
				myCategoryElements[j].thisCategory=this;
				myCategoryElements[j].href+=this.id;
				myCategoryElements[j].onclick=function () {
					var myPointer=this.parentNode;
					var myForm=document.createElement("form");
					myForm.action=this.href;
					myForm.method="POST";
					myForm.setAttribute("myFor",this.getAttribute("myFor")) ;
					var myInput=document.createElement("input");
					myInput.type="text";
					myInput.name="name";
					myInput.size=10;
					myInput.value=this.thisCategory.name;
					myInput.setAttribute("myExpected","rqd");
					myForm.appendChild(myInput);
					var mySubmit=document.createElement("input");
					mySubmit.type="submit";
					mySubmit.value="Ok";
					myForm.appendChild(mySubmit);
					while (myPointer.children[0]) myPointer.removeChild(myPointer.children[0]);
					myPointer.appendChild(myForm);
					initLoadingElements(myForm);
					myInput.onEnter=function ()  {
						myInput.parentNode.submit();
					}
					return false;
				}
			}
			// It defines the del category button performance
			if (myCategoryElements[j].getAttribute("myProperty") == "delCategory") {
				myCategoryElements[j].href+=this.id;
				initLoadingElements(myCategoryElements[j]);
			}
		}
}

// Equivalent to orderCart or to orderCategoriesList
function orderItemsList() {
	this.myView=null;
	this.blankView=null;
	this.myItemView=null;
	this.items=new Array();

	this.myLoadItemsView=myLoadItemsView;
	
	//This function is similar to the function mySetView of the other objects
	function myLoadItemsView(myItemsView) {
		this.myView=myItemsView;
		myItemsElements=this.myView.getElementsByTagName("*");
		var myItemPointer=null;
		
		for (var i in myItemsElements) {
			if (typeof myItemsElements[i].getAttribute != 'function') continue;
			if (myItemsElements[i].getAttribute("myProperty")=="items") {
				myItemPointer=myItemsElements[i];
				break;
			}
		}
		for (var i=0; i<this.items.length; i++) {
			myItemPointer.parentNode.appendChild(this.items[i].myView);
		}

		// we remove the template
		myItemPointer.parentNode.removeChild(myItemPointer);
	}
}
// Equivalent to above
function orderCategoriesList() {
	this.myView=null;
	this.blankView=null;
	this.myCategoryView=null;
	this.rootCategory=null;

	this.myLoadCategoriesView=myLoadCategoriesView;
	
	//This function is similar to the function mySetView of the other objects
	function myLoadCategoriesView(myCategoriesView) {
		
		var categoryPointer=this.rootCategory;
		for (var i in myCatalog.myCategoriesList.rootCategory.categories) {
			if (myCatalog.myCategoriesList.rootCategory.categories[i].selected) {
				categoryPointer=myCatalog.myCategoriesList.rootCategory.categories[i];
				break;
			}
		}
		
		this.myView=myCategoriesView;
		myCategoriesElements=this.myView.getElementsByTagName("*");
		var domTpPointer=null;
		
		for (var i in myCategoriesElements) {
			if (typeof myCategoriesElements[i].getAttribute != 'function') continue;
			if (myCategoriesElements[i].getAttribute("myProperty")=="categories") {
				domTpPointer=myCategoriesElements[i];
				break;
			}
		}

		for (var i=0; i<categoryPointer.categories.length; i++) {
			//var myCategory=categoryPointer.getCategoryByOrder(i+1);
			var myCategory=categoryPointer.categories[i];
			domTpPointer.parentNode.appendChild(myCategory.myView);
		}

		// we remove the template
		domTpPointer.parentNode.removeChild(domTpPointer);
	}
}
/*
 * It defines the item object.
 */
function smallItem() {	
	this.id=null;
	this.name=null;
	this.description=null;
	this.image=null;
	this.price=null;
	this.myView=null;
	this.sort_order=null;

	this.setFromArray=setFromArray;
	this.mySetView=mySetView;
	
	// This function generates the item view from the template item view
	function mySetView(myItemView) {
		this.myView=myItemView;
		var myItemElements=this.myView.getElementsByTagName("*");
		// It will search for the elements that correspond with the properties names to fill them
		for (var j in myItemElements) {
			if (typeof myItemElements[j].getAttribute != 'function') continue;
			if (myItemElements[j].getAttribute("myProperty") in this) {
				myItemElements[j].innerHTML+=this[myItemElements[j].getAttribute("myProperty")];
			}
		}
		// it adds some details that are not filled by the normal properties and the add to the cart performance to the button
		myItemElements=this.myView.getElementsByTagName("*");
		for (var j in myItemElements) {
			if (typeof myItemElements[j].getAttribute != 'function') continue;
			// It modifies the href of the item name for adding it the item id that it is necessary for the destination href script to identify the product
			if (myItemElements[j].getAttribute("myProperty") == "itemLink") {
				myItemElements[j].href=myItemElements[j].href+this.id;
				initLoadingElements(myItemElements[j]);
			}
			if (myItemElements[j].getAttribute("myProperty") == "imageSrc") {
				myItemElements[j].src=this.image;
			}
			if (myItemElements[j].getAttribute("myProperty") == "price") {
				myItemElements[j].innerHTML+=" &euro;";
				
			}
			if (myItemElements[j].getAttribute("myProperty") == "add") {
				myItemElements[j].smallItem=this;
				initAddItemButtons(myItemElements[j]);
			}
			// It defines the edit category button performance
			if (myItemElements[j].getAttribute("myProperty") == "editName") {
				myItemElements[j].thisItem=this;
				myItemElements[j].href+=this.id;
				myItemElements[j].onclick=function () {
					var myPointer=this.parentNode;
					var myForm=document.createElement("form");
					myForm.action=this.href;
					myForm.method="POST";
					myForm.setAttribute("myFor",this.getAttribute("myFor")) ;
					var myInput=document.createElement("input");
					myInput.type="text";
					myInput.name="name";
					myInput.size=30;
					myInput.value=this.thisItem.name;
					myInput.setAttribute("myExpected","rqd");
					myForm.appendChild(myInput);
					var mySubmit=document.createElement("input");
					mySubmit.type="submit";
					mySubmit.value="Ok";
					myForm.appendChild(mySubmit);
					while (myPointer.children[0]) myPointer.removeChild(myPointer.children[0]);
					myPointer.appendChild(myForm);
					initLoadingElements(myForm);
					myInput.onEnter=function ()  {
						myInput.parentNode.submit();
					}
					return false;
				}
			}
			if (myItemElements[j].getAttribute("myProperty") == "editDesc") {
				myItemElements[j].thisItem=this;
				myItemElements[j].href+=this.id;
				myItemElements[j].onclick=function () {
					var myPointer=this.parentNode;
					var myForm=document.createElement("form");
					myForm.action=this.href;
					myForm.method="POST";
					myForm.setAttribute("myFor",this.getAttribute("myFor")) ;
					var myTextArea=document.createElement("textarea");
					myTextArea.name="name";
					myTextArea.cols=50;
					myTextArea.rows=12;
					myTextArea.value=this.thisItem.description;
					myTextArea.setAttribute("myExpected","rqd");
					myForm.appendChild(myTextArea);
					var mySubmit=document.createElement("input");
					mySubmit.type="submit";
					mySubmit.value="Ok";
					myForm.appendChild(mySubmit);
					while (myPointer.children[0]) myPointer.removeChild(myPointer.children[0]);
					myPointer.appendChild(myForm);
					initLoadingElements(myForm);
					myTextArea.onEnter=function ()  {
						myTextArea.parentNode.submit();
					}
					return false;
				}
			}
		}
		//Descriptions have new nodes. That means that we deal a part or the for bucle will get wrong
		myItemElements=this.myView.getElementsByTagName("*");
		for (var j in myItemElements) {
			if (typeof myItemElements[j].getAttribute != 'function') continue;
			// It modifies the href of the item name for adding it the item id that it is necessary for the destination href script to identify the product
			if (myItemElements[j].getAttribute("myProperty") == "shortDescription") {
				myItemElements[j].innerHTML+=this.description;
			}
			if (myItemElements[j].getAttribute("myProperty") == "largeDescription") {
				myItemElements[j].innerHTML+=this.description;
				
			}
		}
	}
	// An accessory function to fill an object properties with other object properties
	function setFromArray(obj) {
		for(var key in obj) {
			if (key in this)
				this[key] = obj[key];
		}
	}
}